package edu.psu.collegerecommendationhelper.algorithm;

import java.util.ArrayList;

import weka.core.Attribute;
import weka.core.FastVector;
import weka.core.Instance;
import weka.core.Instances;
import weka.core.SparseInstance;
import edu.psu.collegerecommendationhelper.model.DemographicInfo;
import edu.psu.collegerecommendationhelper.model.EducationInfo;
import edu.psu.collegerecommendationhelper.model.PreferenceInfo;



@SuppressWarnings("deprecation")
public class UserToClassifierTranslator {

	private ClassifierData classData;
	private Attribute classAtt;
	private Attribute att1;
	private Attribute att2;
	private Attribute att3;
	private Attribute att4;
	private Attribute att5;
	private Attribute att6;
	private Attribute att7;
	private Attribute att8;
	private Attribute att9;
	private Attribute att10;
	private Attribute att11;
	private Attribute att12;
	private Attribute att13;
	private Attribute att14;
	private Attribute att15;
	private Attribute att16;
	private Attribute att17;
	private Attribute att18;
	private Attribute att19;
	private Attribute att20;
	private Attribute att21;
	private Attribute att22;
	private Attribute att23;
	private Attribute att24;
	private Attribute att25;
	private Attribute att26;
	private Attribute att27;
	private Attribute att28;
	private Attribute att29;
	private Attribute att30;
	private Attribute att31;
	
	public UserToClassifierTranslator() {
		classData = new ClassifierData();
	
		  classAtt = new Attribute("theClass");
		  att1 = new Attribute("STUFACR");
		  att2 = new Attribute("EFTOTLT");
		  att3 = new Attribute("EFAIANT");
		  att4 = new Attribute("EFASIAT");
		  att5 = new Attribute("EFBKAAT");
		  att6 = new Attribute("EFHISPT");
		  att7 = new Attribute("EFNHPIT");
		  att8 = new Attribute("EFWHITT");
		  att9 = new Attribute("EFUNKNT");
		  att10 = new Attribute("EFNRALT");   	
		  
		  att11 = new Attribute("STABBR");
		  att12 = new Attribute("EFTOTLM");
		  att13 = new Attribute("EFTOTLF");
		  att14 = new Attribute("INSTSIZE");
		  att15 = new Attribute("OPENPUBL");
		  att16 = new Attribute("ADMCON1");
		  att17 = new Attribute("SATVR25");
		  att18 = new Attribute("SATVR75");
		  att19 = new Attribute("SATMT25");
		  att20 = new Attribute("SATMT75");
		  att21 = new Attribute("SATWR25");
		  att22 = new Attribute("SATWR75");
		  att23 = new Attribute("ACTCM25");
		  att24 = new Attribute("ACTCM75");
		  att25 = new Attribute("ACTEN25");
		  att26 = new Attribute("ACTEN75");
		  att27 = new Attribute("ACTMT25");
		  att28 = new Attribute("ACTMT75");
		  att29 = new Attribute("ACTWR25");
		  att30 = new Attribute("ACTWR75");
		  att31 = new Attribute("CREDITS3");
		  

	}
	
	public ClassifierData translateData(DemographicInfo demogrInfo,
			EducationInfo edu, PreferenceInfo pref) {
				
		classData.setACTComp25(edu.getReadACT());
		classData.setACTComp75(edu.getReadACT());
		classData.setACTEng25(edu.getEnglishACT());
		classData.setACTEng75(edu.getEnglishACT());
		classData.setACTMath25(edu.getMathACT());
		classData.setACTMath75(edu.getMathACT());
		//classData.setACTWriting25();
		//classData.setACTWriting75();
		classData.setAfricanRace(demogrInfo.getRace());
		//classData.setAge(demogrInfo.getAge());
		classData.setAmerIndRace(demogrInfo.getRace());
		//classData.setAPCredit();
		classData.setAsianRace(demogrInfo.getRace());
		classData.setHawaiianRace(demogrInfo.getRace());
		classData.setHighschoolGPA(edu.getGPA());
		classData.setHispRace(demogrInfo.getRace());
		classData.setNonResidentAlienRace(demogrInfo.getRace());
		classData.setPublicPrivate(pref.getPubpri());
		classData.setSATMath25(edu.getMathSAT());
		classData.setSATMath75(edu.getMathSAT());
		classData.setSATReading25(edu.getCreadSAT());
		classData.setSATReading75(edu.getCreadSAT());
		classData.setSATWriting25(edu.getWriteSAT());
		classData.setSATWriting75(edu.getWriteSAT());
		//classData.setSchoolSize(iNSTSIZE);
		
		classData.setStateAbbr(pref.getLocation());
		classData.setStudentFacultyRation(pref.getSexratio());
		
		if ("male" == demogrInfo.getSex()) 
		{
			classData.setTotalMales(1);
		}
		else if ("female" == demogrInfo.getSex())
		{
			classData.setTotalFemales(1);
		}
		else
		{
			classData.setTotalMales(0);
			classData.setTotalFemales(0);
		}
		
		classData.setSchoolSize(pref.getSize());
		classData.setUnknownRace(demogrInfo.getRace());
		classData.setWhiteRace(demogrInfo.getRace());
		
		
		return classData;
		
	}

	public Instances createTestInstances(ClassifierData classData) {	
		 ArrayList<Attribute> atts = new ArrayList<Attribute>();
		 Instance userData = new SparseInstance(29);
		 
		 atts.add(classAtt);
	     atts.add(att1);
	     atts.add(att2);
	     atts.add(att3);
	     atts.add(att4);
	     atts.add(att5);
	     atts.add(att6);
	     atts.add(att7);
	     atts.add(att8);
	     atts.add(att9);
	     atts.add(att10);
	     atts.add(att11);
	     atts.add(att12);
	     atts.add(att13);
	     atts.add(att14);
	     atts.add(att15);
	     atts.add(att16);
	     atts.add(att17);
	     atts.add(att18);
	     atts.add(att19);
	     atts.add(att20);
	     atts.add(att21);
	     atts.add(att22);
	     atts.add(att23);
	     atts.add(att24);
	     atts.add(att25);
	     atts.add(att26);
	     atts.add(att27);
	     atts.add(att28);
	     atts.add(att29);
	     atts.add(att30);
	     atts.add(att31);
	     
	     Instances testSet = new Instances("test", atts, 1);           	     
	     testSet.setClassIndex(0);   
	          
	     int i = 0;
	     userData.setValue((Attribute)atts.get(i), 0);
	     userData.setValue((Attribute)atts.get(i++), classData.getStudentFacultyRation());     
	     userData.setValue((Attribute)atts.get(i++), classData.getTotalSize());
	     userData.setValue((Attribute)atts.get(i++), classData.getAmerIndRace());
	     userData.setValue((Attribute)atts.get(i++), classData.getAsianRace());
	     userData.setValue((Attribute)atts.get(i++), classData.getAfricanRace());
	     userData.setValue((Attribute)atts.get(i++), classData.getHispRace());
	     userData.setValue((Attribute)atts.get(i++), classData.getHawaiianRace());
	     userData.setValue((Attribute)atts.get(i++), classData.getWhiteRace());
	     userData.setValue((Attribute)atts.get(i++), classData.getUnknownRace());
	     userData.setValue((Attribute)atts.get(i++), classData.getNonResidentAlienRace());	
	     userData.setValue((Attribute)atts.get(i++), 0);
	     userData.setValue((Attribute)atts.get(i++), classData.getTotalMales());
	     userData.setValue((Attribute)atts.get(i++), classData.getTotalFemales());
	     userData.setValue((Attribute)atts.get(i++), classData.getSchoolSize());
	     userData.setValue((Attribute)atts.get(i++), classData.getPublicPrivate());
	     userData.setValue((Attribute)atts.get(i++), classData.getHighschoolGPA());
	     userData.setValue((Attribute)atts.get(i++), classData.getSATReading25());
	     userData.setValue((Attribute)atts.get(i++), classData.getSATReading75());
	     userData.setValue((Attribute)atts.get(i++), classData.getSATMath25());
	     userData.setValue((Attribute)atts.get(i++), classData.getSATMath75());
	     userData.setValue((Attribute)atts.get(i++), classData.getSATWriting25());
	     userData.setValue((Attribute)atts.get(i++), classData.getSATWriting75());
	     userData.setValue((Attribute)atts.get(i++), classData.getACTComp25());
	     userData.setValue((Attribute)atts.get(i++), classData.getACTComp75());
	     userData.setValue((Attribute)atts.get(i++), classData.getACTEng25());
	     userData.setValue((Attribute)atts.get(i++), classData.getACTEng75());
	     userData.setValue((Attribute)atts.get(i++), classData.getACTMath25());
	     userData.setValue((Attribute)atts.get(i++), classData.getACTMath75());
	     userData.setValue((Attribute)atts.get(i++), classData.getACTWriting25());
	     userData.setValue((Attribute)atts.get(i++), classData.getACTWriting75());
	     userData.setValue((Attribute)atts.get(i++), classData.getAPCredit());
	     
	     testSet.add(userData);
	     
	     return testSet;
	}
}
